import React, { Component } from "react";

export default class Fetch extends Component {
    render() {
        return (
            <div>
                <button onClick={this.getGoods}>获取商品数据</button>
            </div>
        );
    }

    getGoods = () => {
        //发送请求, 获取商品数据
        // console.log(fetch('http://api.xiaohigh.com/goods'));
        fetch('http://api.xiaohigh.com/goods')
        .then(res => {
            //获取 JSON 响应体解析之后的结果值
            // return res.json();
            //获取原始的响应体
            return res.text();
        }).then(data => {
            console.log(data);
        });
    };
}
